package com.kuang.demo.controller.wx;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bo.zzywx.detail.FinallySpecification;
import com.kuang.demo.bo.zzywx.goods.*;
import com.kuang.demo.service.wx.WXGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/wx/goods")
public class WXGoodsController {

    @Autowired
    WXGoodsService wxGoodsService;

    @RequestMapping("/category")
    public BaseRespVo zzy1(int id){
        ReCategory reCategory = wxGoodsService.selectCategory(id);

        return BaseRespVo.ok(reCategory);
    }

    //
    @RequestMapping("/list")
    public BaseRespVo listGoods(WxCategoryBO categoryBO) {
        WxGoodsListVO wxGoodsListVO = new WxGoodsListVO();
        if (categoryBO.getKeyword()==null && categoryBO.getIsNew()==null &&categoryBO.getIsHot()==null &&categoryBO.getBrandId()==null){
            List<WxGoodsInfo> wxGoodsInfos = wxGoodsService.selectGoods(categoryBO.getSize(),
                    categoryBO.getCategoryId(), categoryBO.getPage());
            wxGoodsListVO.setGoodsList(wxGoodsInfos);
            wxGoodsListVO.setCount(wxGoodsInfos.size());
            wxGoodsListVO.setFilterCategoryList(null);
        }else if(categoryBO.getKeyword()!=null){
            List<WxGoodsInfo> wxGoodsInfos = wxGoodsService.selectGoodsByKeyword(categoryBO.getPage(),
                    categoryBO.getKeyword(), categoryBO.getSize(),categoryBO.getSort(),categoryBO.getOrder());
            wxGoodsListVO.setGoodsList(wxGoodsInfos);
            wxGoodsListVO.setCount(wxGoodsInfos.size());
            wxGoodsListVO.setFilterCategoryList(null);
        }else if (categoryBO.getIsNew()!=null){
            List<WxGoodsInfo> wxGoodsInfos=wxGoodsService.selectHotAndNewGoods(categoryBO);
            wxGoodsListVO.setGoodsList(wxGoodsInfos);
            wxGoodsListVO.setCount(wxGoodsInfos.size());
            wxGoodsListVO.setFilterCategoryList(null);
        }else if (categoryBO.getIsHot()!=null){
            List<WxGoodsInfo> wxGoodsInfos=wxGoodsService.selectHotAndNewGoods(categoryBO);
            wxGoodsListVO.setGoodsList(wxGoodsInfos);
            wxGoodsListVO.setCount(wxGoodsInfos.size());
            wxGoodsListVO.setFilterCategoryList(null);
        }else if (categoryBO.getBrandId()!=null){
            List<WxGoodsInfo> wxGoodsInfos=wxGoodsService.selectHotAndNewGoods(categoryBO);
            wxGoodsListVO.setGoodsList(wxGoodsInfos);
            wxGoodsListVO.setCount(wxGoodsInfos.size());
            wxGoodsListVO.setFilterCategoryList(null);
        }
        return BaseRespVo.ok(wxGoodsListVO);
    }

    @RequestMapping("/count")
    public BaseRespVo zzy3(){
        ReCount reCount = wxGoodsService.selectCountGoods();
        return BaseRespVo.ok(reCount);
    }

    @RequestMapping("/detail")
    public BaseRespVo zzy4(int id){
        FinallySpecification finallySpecification = wxGoodsService.selectGoodsDetail(id);

        return BaseRespVo.ok(finallySpecification);
    }

    @RequestMapping("/related")
    public BaseRespVo zzy5(int id){
        List<ReRelated> goodsList = wxGoodsService.selectRelated(id);
        ReRelatedList reRelatedList = new ReRelatedList();
        reRelatedList.setGoodsList(goodsList);

        return BaseRespVo.ok(reRelatedList);
    }
}
